<?php

namespace App\Http\Middleware;

use Closure;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
       if(!$request->session()->has('adminuser')){

              return redirect('/Admin/login');
       } 

       // //判断是否是超级用户
       if(session('adminuser')->username == "李耀") { 

          return $next($request);
       }

       //判断权限
       $nodelist = session('nodelist');

       foreach($nodelist as $k => $v){
      
            if($request->is('Admin/'.$v['path']) && $request->isMethod($v['mode'])){
                return $next($request);
               
            }
        }

        return back()->with("error","抱歉你没有此操作权限!");

    }










}
